import store from '@/store';
import axios from 'axios';

const serves = axios.create({
    baseURL: 'http://xianyingmo.cn:8080', // 设置请求的基础URL
    timeout: 10000 // 请求超时时间，如果超时10s就不再等待服务器
});

// 请求拦截器
serves.interceptors.request.use(config => {
    const token = store.state.token
    // const token = localStorage.getItem('token');
    if (token) {
        config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
}, err => {
    return Promise.reject(err)
})

// 响应拦截器
serves.interceptors.response.use((res) => {
    // console.log('成功');
    return res
}, err => {
    console.log('失败');
    return err
})



export default serves;
